<template>
  <div class="clearfix check-tb">
      <ul class="fl" v-for="(item, index) in tableList" :key="index" v-bind:style="{width: (1/tableList.length *100)+'%'}">
        <li class="title">{{roundList[index]}}</li>
        <li v-for="(game, listindex) in item" :key="listindex" class="relative game-item">
          <el-row>
            <el-col class="center" v-if="index === 0">
              <keep-alive>
                <team-group :key="listindex + keyValue" :keyLength="listindex + keyValue" :total="total" @valueChange="setTableList" v-if="isedit == 'no'" :valuedata="race_weedout_vslist[listindex + keyValue]"></team-group>
                <team-group :key="listindex + keyValue" :keyLength="listindex + keyValue" :total="total" @valueChange="setTableList" v-if="isedit == 'yes' && race_weedout_vslist.length == (total/2)" :valuedata="race_weedout_vslist[listindex + keyValue]"></team-group>
              </keep-alive>
            </el-col>
            <span v-else></span>
          </el-row>
        </li>
      </ul>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import TeamGroup from './TeamGroup'
export default {
  components: {
    TeamGroup
  },
  props: {
    total: {
      type: Number,
      default: 8
    },
    currentTab: {
      type: Number,
      default: 1
    },
    isedit: {
      type: String,
      default: 'yes'
    }
  },
  computed: {
    ...mapGetters({
      race_weedour_teamlist: 'race_weedour_teamlist',
      race_weedout_vslist: 'race_weedout_vslist'
    }),
    keyValue: function () {
      if (this.total === 8) {
        return (this.currentTab - 1) * 2
      } else if (this.total === 16) {
        return (this.currentTab - 1) * 4
      } else if (this.total === 32) {
        return (this.currentTab - 1) * 4
      } else if (this.total === 64) {
        return (this.currentTab - 1) * 8
      } else {
        return (this.currentTab - 1) * 16
      }
    }
  },
  created () {
    this.calcRound()
  },
  data () {
    return {
      loading: true,
      tableList: [
        new Array(4),
        new Array(2),
        new Array(1)
      ],
      roundList: []
    }
  },
  methods: {
    calcRound () {
      var list = []
      switch (this.total) {
        case 8: list = ['1/4决赛', '半决赛', '决赛']; break // 8支
        case 16: list = ['第一轮', '1/4决赛', '半决赛', '决赛']; this.tableList.unshift(new Array(8)); break // 16支
        case 32: list = ['第一轮', '第二轮', '1/4决赛']; break // 32支
        case 64: list = ['第一轮', '第二轮', '第三轮', '1/4决赛']; this.tableList.unshift(new Array(8)); break // 64支
        case 128: list = ['第一轮', '第二轮', '第三轮', '第四轮', '1/4决赛']; this.tableList.unshift(new Array(16), new Array(8)); break // 128支
      }
      this.roundList = list
    },
    setTableList (val, keyLength) { // 更新对阵数据
      this.$set(this.race_weedout_vslist, keyLength, val)
    }
  }
}
</script>

<style lang="scss" scoped>
  .center{
    text-align: center;
  }
  .game-name{
    width: 100px;
    display: inline-block;
  }
  .seed-number{
    width:20px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    background: #fd9a4c;
    color:#fff;
    display: inline-block;
    border-radius: 3px;
    margin-right: 3px;
    font-size: 12px;
    float: left;
  }
  .player{
    max-width:120px;
    font-size: 12px;
    display: inline-block;
    float: left;
  }
  .scorebtn{
    position: absolute;
    top:38%;
    right:10px;
    margin: 0;
  }
  .check-tb ul li{
    border:1px solid #eee;
    border-bottom: 0;
    border-right: 0;
    padding:13px 10px 0px 10px;
    height: 131px;
  }
  .check-tb ul:last-child{
    border-right: 1px solid #eee;
  }
  .check-tb ul li:last-child{
    border-bottom: 1px solid #eee;
  }
  .check-tb ul:nth-child(2){
    li{
      height:262px;
      padding: 40px 10px 40px 20px; 
      .player-item{
        line-height: 40px;
      }
      .seed-number{
        margin-top: 10px;
      }
      .vs{
        margin: 36px 0
      }
      .scorebtn{
        top:42%;
      }
    }    
  }
  .check-tb ul:nth-child(3){
    li{
      height:524px;
      padding: 150px 10px 100px 20px;
      .player-item{
        line-height: 80px;
      }
      .seed-number{
        margin-top: 30px;
      }
      .scorebtn{
        top:46.5%;
      }
    }    
  }
  .check-tb ul:nth-child(4){
    li{
      height:1048px;
      padding: 250px 10px 100px 20px;
      .player-item{
        line-height: 160px;
      }
      .seed-number{
        margin-top: 70px;
      }
      .vs{
        margin:104px 0
      }
      .scorebtn{
        top:48.5%;
      }
    }    
  }
  .check-tb ul:nth-child(5){
    li{
      height:2096px;
      padding: 500px 10px 200px 20px;
      .player-item{
        line-height: 320px;
      }
      .seed-number{
        margin-top: 150px;
      }
      .vs{
        margin:216px 0
      }
      .scorebtn{
        top:49.2%;
      }
    }    
  }
  .check-tb ul.fl li.title{
    height:40px;
    padding: 0;
    line-height: 40px;
    text-align: center;
  }
</style>
